use anyhow::Result;
use std::fs;
// use prost_build::Config;

fn main() -> Result<()> {
    fs::create_dir_all("src/pb")?;
    // let mut  config = Config::new();
    // config.out_dir("src/pb").type_attribute(".*", "#[derive(Serialize, Deserialize, Clone, Debug, Default)]");
    // config.compile_protos(&["../protos/messages.proto"],&["../protos"])?;
    // Ok(())
    tonic_prost_build::configure()
        .out_dir("src/pb")
        // .message_attribute(".","#[derive(Serialize)] #[serde(rename_all = \"snake_case\")]")
        .type_attribute(
            "WelcomeRequest",
            "#[derive(derive_builder::Builder)]\n#[builder(setter(into, strip_option), default)]",
        )
        .type_attribute(
            "RecallRequest",
            "#[derive(derive_builder::Builder)]\n#[builder(setter(into, strip_option), default)]",
        )
        .type_attribute(
            "RemindRequest",
            "#[derive(derive_builder::Builder)]\n#[builder(setter(into, strip_option), default)]",
        )
        .field_attribute("WelcomeRequest.content_ids",r#"#[builder(setter(each(name="content_id", into)))]"#)
        .compile_protos(
            &["../protos/crm/messages.proto", "../protos/crm/rpc.proto"],
            &["../protos"],
        )?;
    Ok(())
}
